import os
import openpyxl
from openpyxl.workbook import Workbook
from openpyxl.worksheet.worksheet import Worksheet

mypath = r"D:\work\pythonProject"
class Dofile:
    def doExcelReadDIV(self, fname, stname, minRow=None, maxRow=None
                       , minCol=None, maxCol=None):
        fileName = os.path.join(mypath, fname)

        wk: Workbook = openpyxl.load_workbook(fileName)  # 获取工作簿的对象
        st: Worksheet = wk[stname]  # 通过工作簿对象获取sheet对象
        print(st, type(st))
        # 提取部分数据
        ss = st.iter_rows(min_row=minRow,
                          max_row=maxRow,
                          min_col=minCol,
                          max_col=maxCol,
                          values_only=True)  # 获取sheet页中的值

        l = [i for i in ss]  # 生成列表并返回
        print(f'{l}')
        return l
if __name__ == '__main__':
    df = Dofile()
    df.doExcelReadDIV('apt.xlsx','Sheet1',2,3,2,6)